package tech.aistar.day02.homework;

import tech.aistar.util.ArrayUtil;

import java.util.Arrays;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/7/20 8:34 上午
 */
public class Demo {
    public static void main(String[] args) {
        test01();

        countArrRandomCount();

        System.out.println(getYangHui(3, 2));

        printYangHui(10);
    }

    /**
     *
     * @param i 行数
     * @param j 列数
     */
    public static int getYangHui(int i,int j){
        //1. 找出出口
        if(j==0 || i==j)
            return 1;
        return getYangHui(i-1,j-1) + getYangHui(i-1,j);
    }

    public static void printYangHui(int n){
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <=i; j++) {
                System.out.print(getYangHui(i,j)+"\t");
            }
            System.out.println();
        }
    }

    public static void countArrRandomCount(){
        int[] arr = new int[15];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random()*5+1);
        }
        System.out.println(Arrays.toString(arr));
        System.out.println("===华丽丽的分割线===");

        //1. 去重
        int[] temp = ArrayUtil.delDoubleElement(arr);
        //2. 确定二维数组
        int[][] nums = new int[temp.length][2];

        int pos = 0;

        //3. 对二维数组进行赋值,一行一行进行赋值[通过下标一一赋值]
        //二维数组中每个元素都是一维数组
        //nums[0] = new int[]{1,2,3};
        //nums[0] = {1,2,3};//编译错误

        for (int i = 0; i < temp.length; i++) {//外层循环走一次
            int count = 0;//每个随机数出现的次数
            for (int j = 0; j < arr.length; j++) {//内层循环走全部
                if(temp[i] == arr[j]){
                    count++;
                }
            }
            nums[pos++] = new int[]{temp[i],count};
        }

        System.out.println(Arrays.deepToString(nums));
    }

    public static void test01(){
        //1. 转了500圈
        // 每一圈的边角值
        //每圈的等差是2 , 4 , 6 ,...
        int n = 2;//起始的等差是2,循环圈数
        int i = 1;//中间的值,起始值
        long total = 1L;//计算的结果
        while(n<1001){
            //i+=n;//i = 3      13
            //total+=i;//total = 1 + 3
            //
            //i+=n;//i = 5
            //total+=i;//total = 1 + 3 + 5
            //
            //i+=n;//i = 7
            //total+=i;//total = 1 + 3 + 5 + 7
            //
            //i+=n;//i = 9
            //total+=i;//total = 1 + 3 + 5 + 7 + 9
            for (int j = 0; j < 4; j++) {
                i+=n;
                total+=i;
            }
            n+=2; // n = 4
        }
        System.out.println(total);
    }
}
